<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <!-- <el-form-item label="编码" prop="code">
          <el-input v-model="queryParam.qry_code" placeholder=""></el-input>
        </el-form-item> -->
        <el-form-item label="督办单名称">
          <el-input v-model="queryParam.qry_supervisename" placeholder="请填写督办单名称"></el-input>
        </el-form-item>
        <el-form-item class="qryItem" label="督办类型">
          <el-select v-model="queryParam.qry_superviseobjecttype" clearable>
            <el-option v-for="item in codeModel.superviseobjecttypeList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar class="tl-list-toolbar" currentModuleTableCode="sdProjectSupervise/main" ref="toolbar" :refMainTable="$refs.mainTable" :startColumn="3" @add="openAddDialog('editForm')" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :isDisplayDeleteBatch="false" :isDisplayExport="false" :isDisplayAdd="false" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column> -->
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column label="待处理" width="80px" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <el-tag v-if="isInApprovalList(scope.row)" type="success">是</el-tag>
            <template v-else
              >否</template
            >
          </template>
        </el-table-column>
        <!-- <el-table-column prop="dispdeptcommoncode1" label="省区" width="100px" sortable="custom" sort-by="deptcommoncode1" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="supervisename" label="督办单名称" width="200px" sortable="custom" sort-by="supervisename" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="supervisecode" label="督办单编号" width="110px" sortable="custom" sort-by="supervisecode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="projectid" label="项目ID" width="150px" sortable="custom" sort-by="projectid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="projectname" label="项目名称" width="200px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="projectcode" label="项目编号" width="150px" sortable="custom" sort-by="projectcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="releasedate" label="发布日期" width="170px" sortable="custom" sort-by="releasedate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="dispsuperviseobject" label="督办对象" width="150px" sortable="custom" sort-by="superviseobject" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="superviseobjecttype" label="督办对象类型" width="150px" sortable="custom" sort-by="superviseobjecttype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="superviseobjectcode" label="督办对象编号" width="150px" sortable="custom" sort-by="superviseobjectcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="supervisedeptname" label="督办部门" width="280px" sortable="custom" sort-by="supervisedeptname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="supervisedeptcode" label="督办部门编号" width="150px" sortable="custom" sort-by="supervisedeptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="supervisepeople" label="督办发起人" width="95px" sortable="custom" sort-by="supervisepeople" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="supervisepeoplecode" label="督办发起人工号" width="150px" sortable="custom" sort-by="supervisepeoplecode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="involvingtask" label="涉及任务" width="150px" sortable="custom" sort-by="involvingtask" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="supervisereason" label="督办原因" width="200px" sortable="custom" sort-by="supervisereason" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="superviseperiod" label="督办期限" width="170px" sortable="custom" sort-by="superviseperiod" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="responsiblename" label="责任人" width="80px" sortable="custom" sort-by="responsiblename" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="responsiblecode" label="责任人工号" width="150px" sortable="custom" sort-by="responsiblecode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="ccstaffname" label="抄送人员姓名" width="150px" sortable="custom" sort-by="ccstaffname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="ccstaffcode" label="抄送人员工号" width="150px" sortable="custom" sort-by="ccstaffcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="dispsupervisestate" label="督办状态" width="80px" sortable="custom" sort-by="supervisestate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="superviseresponse" label="督办响应" width="200px" sortable="custom" sort-by="superviseresponse" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applyusername" label="申请人" width="80px" sortable="custom" sort-by="applyusername" align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="applyusercode" label="申请人工号" width="150px" sortable="custom" sort-by="applyusercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="username" label="申请人姓名2" width="150px" sortable="custom" sort-by="username" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="usercode" label="申请人工号2" width="150px" sortable="custom" sort-by="usercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="deptname" label="部门" width="150px" sortable="custom" sort-by="deptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="deptcode" label="部门编码" width="150px" sortable="custom" sort-by="deptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="disporgname" label="公司" width="100px" sortable="custom" sort-by="orgname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="orgcode" label="公司编码" width="150px" sortable="custom" sort-by="orgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="applyorgname" label="申请公司" width="120px" sortable="custom" sort-by="applyorgname" align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="applyorgcode" label="申请公司编码" width="150px" sortable="custom" sort-by="applyorgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="applydeptname" label="申请部门" width="120px" sortable="custom" sort-by="applydeptname" align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="applydeptcode" label="申请部门编码" width="150px" sortable="custom" sort-by="applydeptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="docdate" label="单据日期" width="110px" sortable="custom" sort-by="docdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="docno" label="单据编号" width="150px" sortable="custom" sort-by="docno" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="submitdate" label="提交时间" width="110px" sortable="custom" sort-by="submitdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="dispflowid" label="审批流程" width="100px" sortable="custom" sort-by="flowid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true">
          <template v-slot="scope">
            <el-tag :type="changeStateType(scope.row.state)">
              {{ scope.row.dispstate }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="latestphase" label="最新阶段" width="100px" sortable="custom" sort-by="latestphase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
					<template slot-scope="scope">
						<el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
						<el-tag v-else type="danger">否</el-tag>
					</template>
				</el-table-column> -->
        <!-- <el-table-column prop="projectmanager" label="项目经理" width="150px" sortable="custom" sort-by="projectmanager" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="projectmanagercode" label="项目经理工号" width="150px" sortable="custom" sort-by="projectmanagercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column label="操作" width="100px" header-align="center" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" :disabled="(scope.row.state !== 0 && scope.row.state !== 2) || user.code !== scope.row.applyusercode"
              @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="(scope.row.state !== 0 && scope.row.state !== 2) || user.code !== scope.row.applyusercode"
              @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh" :projectinfo="projectinfo"></tl-edit>
      <tl-approval ref="approvalForm" @refresh="doRefresh"></tl-approval>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlApproval from '../../cbo/cboApprovalNodeIns/approvalOne'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'sdProjectSupervise',
  mixins: [mixin_list],
  components: { tlEdit, tlApproval },
  data() {
    return {
      description: 'SD项目督办-列表查询',
      urlPrefix: '/sd/projectSupervise/',
      url: {
        queryCodeList: '/sd/projectSupervise/dataCodeList',
        queryApprovalList: '/cbo/approvalNodeIns/queryApprovalList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'state',
        sord: 'desc'
      },
      approvalDataList: [],
      reduceHeight: 194,
      sourcetype: 'GpmProjectSupervise',
      queryParam: {
        qry_projectid: this.projectinfo.id
      }
    }
  },
  props: {
    projectinfo: {}
  },
  methods: {
    // 审批结束后刷新列表和顶部tab
    doRefresh() {
      this.loadData({})
      this.$emit('refreshIndex')
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    // 打开审批页面
    openApprovalDialog(id) {
      var temp = this.approvalDataList.filter((item) => item.sourceid === id)
      this.$refs.approvalForm.nodeInsId = temp[0].id
      this.$refs.approvalForm.visible = true
    },
    // 双击事件
    doRowDbClick(row, column, event) {
      if (this.isInApprovalList(row)) {
        // 判断是否可以审批
        this.openApprovalDialog(row.id)
      } else {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    beforeLoadData() {
      this.getApprovalDataList()
      return true
    },
    // 获取用户当前待审批列表 =>approvalDataList
    getApprovalDataList() {
      // 参数 在com.topscomm.sd.cboController.CboApprovalNodeInsController#queryApprovalList 里面
      let approvalParam = {
        qry_sourcetype: this.sourcetype,
        qry_approvaluserid: this.user.id,
        sidx: 'nodeins.createon',
        currentPage: '1',
        pageSize: '1000'
      }
      getAction(this.url.queryApprovalList, approvalParam)
        .then((res) => {
          if (res.success) {
            this.approvalDataList = res.result.dataList
          }
        })
        .catch((err) => {
          this.$tap.alert(err, 'warninig')
        })
    },
    isInApprovalList(row) {
      return this.approvalDataList.filter((item) => item.sourceid === row.id).length > 0
    },
    /** 改变审核状态标签颜色 */
    changeStateType(state) {
      return state === 0 ? 'info' : state === 2 ? 'danger' : state === 9 ? 'success' : ''
    }
  }
}
</script>

<style scoped>
.app-container {
  margin: 0;
}
</style>
